package com.zzyl;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * TODO
 *
 * @Author mr.li
 * @Date 2025/7/26 10:03
 */

@SpringBootTest
public class SpringDataRedisTest2 {

    @Autowired
    private RedisTemplate redisTemplate;


    @Test
    public void testString(){
        redisTemplate.opsForValue().set("name","张三");
        Object name = redisTemplate.opsForValue().get("name");
        System.out.println(name);

        //设置一个存在不更新的值
        redisTemplate.opsForValue().setIfAbsent("lock" ,"1");
        Object o = redisTemplate.opsForValue().get("lock");
        System.out.println(o);
    }

    @Test
    public void  testHash(){

        redisTemplate.opsForHash().put("hash","name","zhangsi");

        Object name = redisTemplate.opsForHash().get("hash", "name");
        System.out.println(name);
    }

    @Test
    public  void  testList(){
        //帮我展示redis中list列表的所有方法

        redisTemplate.opsForList().leftPushAll("list","wangwu","zhaoliu","tianqi");
        Long size = redisTemplate.opsForList().size("list");
        System.out.println("size："+size);

//        System.out.println(redisTemplate.opsForList().leftPop("list"));
    }


}
